import 'package:dio/dio.dart';
import 'package:flutter_changdian_football/api/api.dart';
import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/http_utils.dart';
import 'package:flutter_changdian_football/global.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class ReqCourt {

  /// 获取可选择的场地列表 场地选择列表
  static Future<ApiResponse<dynamic>> courtList(String regionCode) async {
    try {
      var response = await HttpUtils.post(Api.courtList, data: {
        'regionCode': regionCode
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 首页-附近场地-本地球场-关键字查询球场
  static Future<ApiResponse<dynamic>> nearbyCourts({
    String? keyword,
    int pageNum = 1,
    String? pcode,
    String? lng,
    String? lat,
  }) async {
    try {
      var response = await HttpUtils.post(Api.nearbyCourts, data: {
        "keyword": keyword,
        "pageNum": pageNum,
        "pageSize": Global.pageSize,
        "pcode": pcode,
        'queryType': 'LOCAL',
        'lng': lng,
        'lat': lat
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 场地详情
  static Future<ApiResponse<dynamic>> courtDetail({
    String? courtId,
    String? lng,
    String? lat,
  }) async {
    try {
      var response = await HttpUtils.post(Api.courtDetail, data: {
        "courtId": courtId,
        "lat": lat,
        "lng": lng
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

}